package web.servlet;

import domain.Account;
import service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "CheckPasswordServlet", urlPatterns = {"/CheckPassword"})
public class CheckPasswordServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = ((Account) req.getSession().getAttribute("loginUser")).getUserid();
        System.out.println(id);
        String password = req.getParameter("password");

        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();
        Account account = new AccountService().confirmUserByIdAndPassword(id, password);
        if(account == null){
            out.print("Different");
        }else {
            out.print("Same");
        }
    }
}
